package com.deer.wms.inventory.web;

import com.deer.wms.inventory.model.combinePallet.CombinePalletTaskDetail;
import com.deer.wms.inventory.model.combinePallet.CombinePalletTaskDetailCriteria;
import com.deer.wms.inventory.service.CombinePalletTaskDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by  on 2020/06/14.
*/
@RestController
@RequestMapping("/combine/pallet/task/details")
public class CombinePalletTaskDetailController {

    @Autowired
    private CombinePalletTaskDetailService combinePalletTaskDetailService;

    @PostMapping("/add")
    public Result add(@RequestBody CombinePalletTaskDetail combinePalletTaskDetail) {
        combinePalletTaskDetailService.save(combinePalletTaskDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(  Integer id) {
        combinePalletTaskDetailService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody CombinePalletTaskDetail combinePalletTaskDetail) {
        combinePalletTaskDetailService.updateById(combinePalletTaskDetail);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        CombinePalletTaskDetail combinePalletTaskDetail = combinePalletTaskDetailService.getById(id);
        return ResultGenerator.genSuccessResult(combinePalletTaskDetail);
    }

    @GetMapping("/list")
    public Result list(CombinePalletTaskDetailCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<CombinePalletTaskDetail> list = combinePalletTaskDetailService.list();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
